<template>
  <div style="display: inline-block; margin-top: 20px">
    <div class="card" v-if="type === 0">
      <div class="photo"><img :src="dataInfo.imageUrl" alt="" /></div>
      <h1>{{ dataInfo.productName }}</h1>
      <h2>{{ dataInfo.productName }}</h2>
      <p>所属类型：{{ dataInfo.typeBriefInfo.productType }}</p>
      <p>产品编码：{{ dataInfo.productCode }}</p>
      <p>产品单位：{{ dataInfo.productUnit }}</p>
      <p>产品型号：{{ dataInfo.productModel }}</p>
      <p>创建者：{{ dataInfo.creator }}</p>
      <p>创建时间：{{ dataInfo.createTime | dateFormat }}</p>
    </div>
    <div class="card" v-if="type === 1">
      <div class="photo">
        <img src="http://image.wicking.xyz/default/default-type.jpg" alt="" />
      </div>
      <h1>{{ dataInfo.productType }}</h1>
      <h2>{{ dataInfo.productType }}</h2>
      <p>创建者：{{ dataInfo.creator }}</p>
      <p>创建时间：{{ dataInfo.createTime | dateFormat }}</p>
      <p>
        {{ dataInfo.description }}
      </p>
    </div>
    <div class="card" v-if="type === 2">
      <div class="photo">
        <img src="http://image.wicking.xyz/default/default-proj.jpg" alt="" />
      </div>
      <h1>{{ dataInfo.projectName }}</h1>
      <h2>{{ dataInfo.projectName }}</h2>
      <p>所属类型：{{ dataInfo.typeBriefInfo.productType }}</p>
      <p>采购产品：{{ dataInfo.productNames.map(product => {
          return product.productName;
        }).join(",") }}</p>
      <p>创建者：{{ dataInfo.creator }}</p>
      <p>创建时间：{{ dataInfo.createTime | dateFormat }}</p>
      <p>
        {{ dataInfo.description }}
      </p>
    </div>
  </div>
</template>

<script>
export default {
  name: "CardPerson",
  props: {
    dataInfo: Object,
    type: Number,
  },
  data() {
    return {};
  },
  filters: {
    dateFormat(dateStr) {
      let dt = new Date(dateStr);
      const y = dt.getFullYear();
      // 月份从0开始,使她变成字符串,不足两位时,前面补个0.
      const m = (dt.getMonth() + 1 + "").padStart(2, "0");
      const d = (dt.getDate() + "").padStart(2, "0");
      return `${y}-${m}-${d}`;
    },
  },
  methods: {},
};
</script>

<style scoped>
.card {
  /* 相对定位 */
  position: relative;
  width: 200px;
  height: 280px;
  margin: 5px;
  background-color: #758a99;
  border-radius: 5px;
  /* 溢出隐藏 */
  overflow: hidden;
  /* 弹性布局 */
  display: flex;
  /* 元素纵向排列 */
  flex-direction: column;
  /* 居中 */
  align-items: center;
  color: #fff;
  /* 阴影 */

  /* 不让其被挤压 */
  flex-shrink: 0;
}
.card .photo img {
  width: 100%;
  height: 100%;
  /* 保持原有尺寸比例，裁切长边 */
  object-fit: cover;
}
/* 默认大图 */
.card .photo {
  /* 绝对定位 */
  position: absolute;
  top: 0;
  width: 100%;
  height: 100%;
  border-radius: 0%;
  overflow: hidden;
  /* 动画过渡 */
  transition: 0.5s;
}
/* 鼠标移入变小图 */
.card:hover .photo {
  top: 15px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.8);
}
/* 这里加个黑色到透明的渐变背景，可以更好的看清楚名字 */
.card .photo::before {
  content: "";
  position: absolute;
  width: 100%;
  height: 100%;
  background: linear-gradient(to bottom, transparent 50%, #222);
}
.card h1 {
  position: absolute;
  top: 67.5px;
  font-size: 25px;
  transition: 0.5s;
}
.card:hover h1 {
  top: 67.5px;
}
.card h2 {
  margin-top: 110px;
  width: 80%;
  border-bottom: 1px solid rgba(255, 255, 255, 0.3);
  font-size: 10px;
  text-align: center;
  margin-bottom: 10px;
  padding-bottom: 10px;
}
.card p {
  width: 90%;
  text-indent: 16px;
  font-size: 8px;
  margin-bottom: 7.5px;
  line-height: 15px;
}
.card a {
  font-size: 7px;
  color: rgba(255, 255, 255, 0.8);
  text-decoration: none;
  border: 1px solid rgba(255, 255, 255, 0.5);
  padding: 4px 16px;
  border-radius: 4px;
}
.card a:hover {
  color: #fff;
  background-color: rgba(255, 255, 255, 0.2);
}
</style>